package com.suxin.algorithm.table;

import io.shardingsphere.api.algorithm.sharding.PreciseShardingValue;
import io.shardingsphere.api.algorithm.sharding.standard.PreciseShardingAlgorithm;
import lombok.extern.slf4j.Slf4j;

import java.util.Collection;

/**
 * @author Tang
 * @classname GoodsTablePreciseShardingAlgorithm
 * @description [  ]
 * @date 2021/3/9 10:32
 */
@Slf4j
public class GoodsTableIdPreciseShardingAlgorithm implements PreciseShardingAlgorithm<Integer> {
    @Override
    public String doSharding(Collection<String> availableTargetNames, PreciseShardingValue<Integer> shardingValue) {
        Integer shardingValueValue = shardingValue.getValue();
        log.info("分表算法参数:可用的表名称集合:{},分片键的值:{}",availableTargetNames, shardingValueValue);
        return "goods_" + (shardingValueValue % 2);
    }
}